//
//  AppDelegate.m
//  FaceRtmpDemo
//
//  Created by acewei on 2021/10/15.
//

#import "AppDelegate.h"

#define Screen_width [UIScreen mainScreen].bounds.size.width
#define Screen_height [UIScreen mainScreen].bounds.size.height

@interface AppDelegate ()

@end

@implementation AppDelegate

@synthesize window = _window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
//    UIViewController *vc = [NSClassFromString(@"RecordVideoVC") new];
//
//    UIWindow *window = [self.class getCurrentWindow] ?: [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, Screen_width, Screen_height)];
//    window.backgroundColor = [UIColor whiteColor];
//    window.rootViewController = vc;
    
    return YES;
}


+(UIWindow*)getCurrentWindow
{
    if([[[UIApplication sharedApplication] delegate] window]) {
        return [[[UIApplication sharedApplication] delegate] window];
    }else{

        if(@available(iOS 13.0, *)) {
            NSArray *array =[[[UIApplication sharedApplication] connectedScenes] allObjects];

            UIWindowScene* windowScene = (UIWindowScene*)array[0];
            //如果是普通App开发，可以使用
//            SceneDelegate * delegate = (SceneDelegate *)windowScene.delegate;
//            UIWindow * mainWindow = delegate.window;
            //由于在sdk开发中，引入不了SceneDelegate的头文件，所以需要用kvc获取宿主app的window.
            UIWindow *mainWindow = [windowScene valueForKeyPath:@"delegate.window"];

            if(mainWindow) {
                return mainWindow;
            }else{
                return [UIApplication sharedApplication].windows.lastObject;
            }
        }else{
            // Fallback on earlier versions
            return [UIApplication sharedApplication].keyWindow;
        }
    }
}

@end
